package com.org.redis.config;

import redis.clients.jedis.Jedis;

public class RedisTemplate implements IRedis {

    private Jedis jedis;

    public RedisTemplate() {
        this(JedisUtils.getJedis());
    }

    public RedisTemplate(Jedis jedis) {
        this.jedis = jedis;
    }

    @Override
    public boolean set(String k, String v, int expires) {
        Long rs = jedis.setnx(k, v);
        if (rs == 0) {
            return false;
        }
        jedis.expire(k, expires);
        return true;
    }

    @Override
    public boolean delete(String k) {
        return jedis.del(k) > 0;
    }
}
